package org.example.controller.iim;

import jakarta.annotation.Resource;
import org.example.domain.Result;
import org.example.domain.iim.Requirements;
import org.example.mapper.RequirementsMapper;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @Author: whopxx
 * @CreateTime: 2025-01-06
 */
@RestController
@RequestMapping("/requirements")
public class RequirementsController {
    @Resource
    private RequirementsMapper requirementsMapper;

    // pid: 项目id
    @GetMapping("/list")
    public Result list(@RequestParam Integer pid) {
        //  获取当前pid项目的所有对象
        List<Requirements> requirements = requirementsMapper.selectByPid(pid);
        return Result.success(requirements);
    }

    @PostMapping
    public Result add(@RequestBody Requirements requirements, @RequestParam Integer pid) {
        requirements.setProjectId(pid);
        requirementsMapper.insert(requirements);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody Requirements requirements,@RequestParam Integer pid) {
        requirements.setProjectId(pid);
        requirementsMapper.myUpdateById(requirements);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam Integer id,@RequestParam Integer pid) {
        requirementsMapper.deleteById(id);
        return Result.success();
    }
}
